package com.tencent.iov.cowin.befsale.clue.controller.clue;

import com.tencent.iov.cowin.befsale.clue.controller.clue.assembler.ClueAssembler;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.*;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.response.ClueIntentionGradeResponse;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.response.ClueResponse;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.response.ClueTaskDataResponse;
import com.tencent.iov.cowin.befsale.clue.controller.cus.vo.request.ClueIntentionGradeDataRequest;
import com.tencent.iov.cowin.befsale.clue.domain.clue.po.Clue;
import com.tencent.iov.cowin.befsale.clue.service.clue.ClueService;
import com.software.boot.common.entity.Response;
import com.software.boot.common.model.dao.PageRequest;
import com.software.boot.common.model.dao.PageResponse;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.AddClueRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.DeleteClueRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.QueryClueRequest;
import com.tencent.iov.cowin.befsale.clue.controller.clue.vo.request.UpdateClueRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Describe: 线索信息表_Controller层
 * @author: whp
 * @created: 2021-12-21 16:16:06
 * @version: 1.0
 */
@RestController
@Api(tags = "线索信息表Controller")
@RequestMapping(value = "/v1/clue", produces = MediaType.APPLICATION_JSON_VALUE)
public class ClueController {

    @Autowired
    private ClueService clueService;

    /**
     * 通过ID获取详细信息
     *
     * @param: id
     * @return: Clue对象
     */
    @ApiOperation(value = "Clue管理-通过ID获取详细信息接口", httpMethod = "GET", response = Response.class, notes = "get_detail_by_id")
    @RequestMapping(path = "/get_detail_by_id", method = RequestMethod.GET)
    public Response<ClueResponse> getDetailById(@ApiParam(required = true, value = "对象ID", defaultValue = "1") @RequestParam("id") Long id) {
        return Response.success(ClueAssembler.transformPOToResponseVo(clueService.getDetailById(id), ClueResponse.class));
    }

    /**
     * 单条数据插入Clue
     *
     * @param request
     * @return 插入的条数
     */
    @ApiOperation(value = "Clue管理-添加信息接口", httpMethod = "POST", response = Response.class, notes = "add")
    @RequestMapping(path = "/add", method = RequestMethod.POST)
    public Response<Integer> add(@Valid @RequestBody AddClueRequest request) {
        return Response.success(clueService.insert(ClueAssembler.transformVOToPO(request, Clue.class)));
    }

    /**
     * 批量插入Clue
     *
     * @param requests
     * @return 批量插入的条数
     */
    @ApiOperation(value = "Clue管理-批量插入Clue接口", httpMethod = "POST", response = Response.class, notes = "add_batch")
    @RequestMapping(path = "/add_batch", method = RequestMethod.POST)
    public Response<Integer> addBatch(@Valid @RequestBody List<QueryClueRequest> requests) {
        return Response.success(clueService.insertBatch(ClueAssembler.transformPOToResponseVoList(requests, Clue.class)));
    }

    /**
     * 通过ID修改信息接口
     *
     * @param: request
     * @return: 修改的条数
     */
    @ApiOperation(value = "Clue管理-修改信息接口", httpMethod = "POST", response = Response.class, notes = "update")
    @RequestMapping(path = "/update", method = RequestMethod.POST)
    public Response<Integer> update(@Valid @RequestBody UpdateClueRequest request) {
        return Response.success(clueService.update(ClueAssembler.transformVOToPO(request, Clue.class)));
    }

    /**
     * 通过ID删除数据
     *
     * @param request
     * @return 删除的条数
     */
    @ApiOperation(value = "Clue管理-通过ID删除接口", httpMethod = "POST", response = Response.class, notes = "delete")
    @RequestMapping(path = "/delete", method = RequestMethod.POST)
    public Response<Integer> delete(@Valid @RequestBody DeleteClueRequest request) {
        return Response.success(clueService.delete(ClueAssembler.transformVOToPO(request, Clue.class)));
    }

    /**
     * 根据条件查询对象list列表
     *
     * @param request
     * @return 查询结果
     */
    @ApiOperation(value = "Clue管理-根据条件查询对象list列表接口", httpMethod = "POST", response = Response.class, notes = "query_list_by_param")
    @RequestMapping(path = "/get_list_by_param", method = RequestMethod.POST)
    public Response<List<ClueResponse>> getListByParam(@RequestBody QueryClueRequest request) {
        List<Clue> responseList = clueService.getListByParam(ClueAssembler.transformVOToPO(request, Clue.class));
        return Response.success(ClueAssembler.transformPOToResponseVoList(responseList, ClueResponse.class));
    }

    /**
     * 根据条件查询对象Page记录
     *
     * @param request
     * @return 查询结果
     */
    @ApiOperation(value = "Clue管理-根据条件查询对象Page记录接口", httpMethod = "POST", response = Response.class, notes = "get_page_by_param")
    @RequestMapping(value = "/get_page_by_param", method = RequestMethod.POST)
    public Response<PageResponse<ClueResponse>> getPageByParam(@RequestBody PageRequest<QueryClueRequest> request) {
        PageResponse<Clue> cluePageResponse = clueService.getPageByParam(ClueAssembler.transformVOToPOPage(request, Clue.class));
        return Response.success(ClueAssembler.transformPOToResponseVoPage(cluePageResponse, ClueResponse.class));
    }

    /**
     * 创建线索 add by 2021-12-23
     * @param request
     * @return
     */
    /*@ApiOperation(value = "创建线索", httpMethod = "POST", response = Response.class, notes = "create_clue_with_follow_up")
    @RequestMapping(value = "/create_clue_with_follow_up", method = RequestMethod.POST)
    public Response createClueWithfollowUp(@RequestBody ClueFollowUpRequest request) {
        Long falg= clueService.createClueWithfollowUp(request);
        return Response.success(falg);
    }*/

    /**
     * 管理看板-线索看板
     * add by zly 2022-01-11
     * @param clueIntentionGradeDataRequest
     * @return
     */
    @ApiOperation(value = "管理看板-线索看板", httpMethod = "POST", response = Response.class, notes = "getIntentionGradeData")
    @RequestMapping(value = "/getClueIntentionGradeData", method = RequestMethod.POST)
    public Response<ClueIntentionGradeResponse> getClueIntentionGradeData(@RequestBody ClueIntentionGradeDataRequest clueIntentionGradeDataRequest){
        ClueIntentionGradeResponse clueIntentionGradeResponse=clueService.getClueIntentionGradeData(clueIntentionGradeDataRequest);
        return Response.success(clueIntentionGradeResponse);
    }
    /**
     * 管理看板-任务看板
     * add by zly 2022-01-13
     * @param clueIntentionGradeDataRequest
     * @return
     */
    @ApiOperation(value = "管理看板-任务看板", httpMethod = "POST", response = Response.class, notes = "getClueTaskData")
    @RequestMapping(value = "/getClueTaskData", method = RequestMethod.POST)
    public Response<ClueTaskDataResponse> getClueTaskData(@RequestBody ClueIntentionGradeDataRequest clueIntentionGradeDataRequest){
        ClueTaskDataResponse clueTaskDataResponse=clueService.getClueTaskData(clueIntentionGradeDataRequest);
        return Response.success(clueTaskDataResponse);
    }

    /**
     * 定时器执行-SCRM通过线索中心将线索下发给下游
     * scrm根据线索状态的规则配置，来定时捞历史跟进的线索数据，通过kafka发送给下游（包括scrm、会员积分、经纪人）
     * 其中scrm也来消费，然后通过接口的形式发送给crm(但是crm是外部系统，所以需要有一层scrm来消费，再调接口发送给crm)
     * 会员积分，经纪人是内部系统，scrm发送kafka，他们消费
     * add by zly
     * 2022-01-22
     * 7=SCRM下发试乘试驾/交车/战败给CRM
     * 8=MQ
     * @return
     */
    @ApiOperation(value = "通过规则配置将线索信息以MQ的形式发送给下游", httpMethod = "GET", response = Response.class, notes = "syncClueByMqToOther")
    @RequestMapping(value = "/syncClueByMqToOther", method = RequestMethod.GET)
    public Response syncClueByMqToOther(@ApiParam(required = false, value = "统计日期,指定到天：yyyy-mm-dd") @RequestParam("sysnTime") String sysnTime){
        clueService.syncClueByMqToOther(sysnTime);
        return Response.success();
    }

}